package com.zzu.view.fragment;

import android.app.ProgressDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zzu.R;
import com.zzu.model.bean.Delivery;
import com.zzu.presenter.impl.PackagePresenterImpl;
import com.zzu.adapter.OneAdapter;
import com.zzu.utils.Constants;
import com.zzu.view.view.PackageQueryView;

import java.util.List;

/**
 * @description:
 * @author: bytedance
 * @date: 2021-05-07 23:35
 * 派送Fragment
 */
public class FragmentOne extends BaseFragment {

    private final String TAG = FragmentZero.class.getSimpleName();

    //输入的派送员id
    EditText ed_one_handle;
    //搜索按钮
    Button bt_one_search;
    //当没有快递信息是的显示布局
    LinearLayout ll_item_empty;
    //显示揽收信息的RecyclerView
    RecyclerView one_recyclerview;

    @Override
    public View initView() {
        Log.e(TAG, "派送任务视图被初始化了");
        View view = View.inflate(mContext, R.layout.fragment_one, null);
        ed_one_handle = view.findViewById(R.id.ed_one_handle);
        bt_one_search = view.findViewById(R.id.bt_one_search);
        ll_item_empty = view.findViewById(R.id.ll_item_empty);
        TextView tv_item_empty = view.findViewById(R.id.tv_item_empty);
        tv_item_empty.setText(Constants.FRAGMENT_EMPTY_ONE);
        one_recyclerview = view.findViewById(R.id.one_recyclerview);

        //添加监听事件
        initListener();

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        //显示揽收的数据，初使显示中原区信息
        showData(ed_one_handle.getText().toString());
    }

    private void initListener() {
        bt_one_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取输入的派送员id
                showData(ed_one_handle.getText().toString());
            }
        });

    }

    private void showData(String id) {
        new PackagePresenterImpl(mContext,new PackageQueryView<List<Delivery>>() {
            @Override
            public void getDates(List<Delivery> datas) {
                Log.i(TAG,"获取派送员为"+id+"的数据:"+datas);
                //查询到数据
                //把当没有数据显示的布局-隐藏
                ll_item_empty.setVisibility(View.GONE);
                OneAdapter adapter = new OneAdapter(mContext,datas);
                one_recyclerview.setAdapter(adapter);
                //设置布局管理器
                one_recyclerview.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
            }

            @Override
            public void getNoDate() {
                //没有数据
                ll_item_empty.setVisibility(View.VISIBLE);
            }
        }).getDeliveryTaskByHandler(id);
    }

    @Override
    public void initData() {
        super.initData();
        Log.e(TAG, "派送任务数据被初始化了");
    }
}
